package com.ve.searcher

import com.ve.searcher.extension.readLines
import org.apache.lucene.analysis.Analyzer
import org.apache.lucene.analysis.CharArraySet
import org.apache.lucene.analysis.cjk.CJKAnalyzer
import org.apache.lucene.analysis.core.SimpleAnalyzer
import org.apache.lucene.analysis.core.StopAnalyzer
import org.apache.lucene.analysis.core.WhitespaceAnalyzer
import org.apache.lucene.analysis.standard.StandardAnalyzer
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute
import org.apache.lucene.analysis.tokenattributes.TypeAttribute
import java.nio.file.Paths


fun main(args: Array<String>) {
    val TOP_WORDS_SET= setOf("a","an","are","at","be","but","such","the","that","their","they" ,"was","will")
    val filepath = "C:\\code\\LR\\RIIL_BMC_AdminConsole\\source\\riil-alarm-3rd-impl\\src\\main\\resources\\entities\\alarmSendRuleDao.xml"
    val text = java.lang.String.join("", Paths.get(filepath).readLines())
    display(text, StandardAnalyzer(CharArraySet(TOP_WORDS_SET,false)))
//    display(text, SimpleAnalyzer())
//    display(text, StopAnalyzer())
//    display(text, WhitespaceAnalyzer())
//    display(text, CJKAnalyzer())


}




fun display(str: String, a: Analyzer) {
    println(">>>>>>>>>>>>>${a.javaClass}")
    val stream = a.tokenStream("renyi", str)
    val pia = stream.addAttribute(PositionIncrementAttribute::class.java)
    val oa = stream.addAttribute(OffsetAttribute::class.java)
    val cta = stream.addAttribute(CharTermAttribute::class.java)
    val ta = stream.addAttribute(TypeAttribute::class.java)
    stream.reset()
    while (stream.incrementToken()) {
        println("${cta.toString()}")
    }
/*
    while (stream.incrementToken()) {
        println("${pia.positionIncrement}:[${cta.toString()}]:${oa.startOffset()}->${oa.endOffset()}:${ta.type()}")
    }
*/
    stream.end()
    println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
}
